package com.purong.purong.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.purong.purong.R;
import com.purong.purong.bean.AreaBean;

import java.util.List;

/**
 * Created by Administrator on 2016/8/22.
 */
public class AreaListAdapter extends BaseAdapter{
    private Context mContext;
    private List<AreaBean> areaList;
    public AreaListAdapter(Context context, List<AreaBean> list){
        this.mContext=context;
        this.areaList=list;
    }
    @Override
    public int getCount() {
        return areaList.size();
    }

    @Override
    public Object getItem(int position) {
        return areaList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder mHolder;
        if (convertView==null){
            convertView= LayoutInflater.from(mContext).inflate(R.layout.dialog_area_item,null);
            mHolder=new ViewHolder(convertView);
            convertView.setTag(mHolder);
        }else {
            mHolder=(ViewHolder)convertView.getTag();
        }
        if (areaList.get(position).isCheck()){
            Log.e("zwj","...check="+areaList.get(position).getAcronym());
            mHolder.acronym.setTextColor(mContext.getResources().getColor(R.color.blue));
            mHolder.acronym.setText(areaList.get(position).getAcronym());
            mHolder.check.setVisibility(View.VISIBLE);
        }else {
            mHolder.acronym.setTextColor(mContext.getResources().getColor(R.color.text_dark_gray));
            mHolder.acronym.setText(areaList.get(position).getAcronym());
            mHolder.check.setVisibility(View.GONE);
        }
        return convertView;
    }
    class ViewHolder{
        private TextView acronym;
        private ImageView check;
        public ViewHolder(View v){
            acronym=(TextView) v.findViewById(R.id.acronym);
            check=(ImageView) v.findViewById(R.id.check);
        }
    }

}
